Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

co-gather

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-gather

Execute thunks in parallel with concurrency support and gather all the results

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.1K
increased by8.19%
Maintainers
1
Weekly downloads
 
Created
Source

co-gather

Execute thunks in parallel with concurrency support and gather all the results.

co-gather is similar with co-parallel, but co-gather will gather all the result of these thunks, even those thunks throw error.

Installation

$ npm install co-gather

Example

var gather = require('co-gather');
var thread = require('co-thread');
var wait = require('co-wait');
var co = require('co');

var index = 0;
function *random() {
  var i = index++;
  yield wait(Math.random() * 100);
  if (Math.random() > 0.5) {
    throw new Error('error');
  }
  return i;
}

co(function *() {
  var ret = yield gather(thread(random, 10));
  console.log(ret);
})();

=>

[
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: false, value: 5 },
  { isError: false, value: 6 },
  { isError: false, value: 7 },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] }
]

API

gather(thunks, [concurrency])

Execute thunks in parallel, with the given concurrency defaulting to 5, and gather the result

License

MIT

Keywords

FAQs

Package last updated on 06 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc